import * as THREE from 'three'
import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js'

// 创建场景
const scene = new THREE.Scene()
// 创建相机
const camera = new THREE.PerspectiveCamera(
  75,
  window.innerWidth / window.innerHeight,
  0.1,
  1000
)
// 创建渲染器

const renderer = new THREE.WebGLRenderer({
  antialias: true,
})
renderer.setSize(window.innerWidth, window.innerHeight)
renderer.shadowMap.enabled = true //开启投影
document.body.appendChild(renderer.domElement) //添加到dom文档中

// 添加光源

const ambientLight = new THREE.AmbientLight(0xffffff) // 创建环境光
scene.add(ambientLight)

const directionLight = new THREE.DirectionalLight(0xffffff, 2.5)
directionLight.castShadow = true
directionLight.position.set(20,120,60)
scene.add(directionLight)


// 加载fbx方法
export const loadFbx = (url) => {
  const fbxLoader = new FBXLoader()
  return new Promise((resolve, reject) => {
    fbxLoader.load(url, (object) => {
      resolve(object)
    }, (progress) => {
      // console.log(progress);
      
    },(error) => {
      reject(error);
    })
  })
}

export {
  scene,
  camera,
  renderer,
}